#include "widget.h"
#include "ui_widget.h"
#include<QListWidgetItem>
#include<QDebug>

Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);
    ui->listWidget->addItem("C++");
    ui->listWidget->addItem("Python");
    ui->listWidget->addItem("Java");
}

Widget::~Widget()
{
    delete ui;
}


void Widget::on_listWidget_currentItemChanged(QListWidgetItem *current, QListWidgetItem *previous)
{
    if(current!=NULL&&previous!=NULL)
    {
        qDebug()<<"当前选中："<<current->text()<<"，之前选中："
               <<previous->text();
    }
}

void Widget::on_pushButton_add_clicked()
{
    const QString s=ui->lineEdit->text();
    if(!s.isEmpty())
    {
        ui->listWidget->addItem(s);
    }
    else
    {
        return;
    }
}

void Widget::on_pushButton_2_clicked()
{
    //获取当前行
    int row=ui->listWidget->currentRow();
    ui->listWidget->takeItem(row);
}
